package com.basedefence.models;

import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;


public class DefaultRocket extends BaseRocket {

	private float DX = (float) 0.0,DY = (float) 2.0;
	private float angleX, angleY, angle = (float) 0.0;
	@Override
	public void doUpdate(long time) {
		float dxTMP,dyTMP;
		DX = (float) 0.0;
		DY = (float) 2.0;
		dxTMP = (float)(DX*Math.cos(angle) - DY*Math.sin(angle));
		dyTMP = (float)(DX*Math.sin(angle) + DY*Math.cos(angle));
		DX = dxTMP;
		DY = dyTMP;
		this.setPosition(this.getX() + dxTMP, this.getY() + dyTMP);
	}
	
	private float m_fOnTouchX;

	@Override
	public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
			float pTouchAreaLocalX, float pTouchAreaLocalY) {
		switch (pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			m_fOnTouchX = pTouchAreaLocalX;
			break;
		case TouchEvent.ACTION_MOVE:
			if(pTouchAreaLocalX > m_fOnTouchX && pTouchAreaLocalX - m_fOnTouchX > 10)
			{
				this.setRotation(this.getRotation() - 2);
				angle +=2;
				m_fOnTouchX = pTouchAreaLocalX - 10;
			}
			if(pTouchAreaLocalX < m_fOnTouchX && m_fOnTouchX - pTouchAreaLocalX > 10)
			{
				this.setRotation(this.getRotation() + 2);
				angle -=2;
				m_fOnTouchX = pTouchAreaLocalX + 10;
			}
			break;
		case TouchEvent.ACTION_UP:
			m_fOnTouchX = 0;
			break;
		}
		return super
				.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
	}
	public DefaultRocket(float pX, float pY,
			ITiledTextureRegion pTiledTextureRegion,
			VertexBufferObjectManager pVertexBufferObjectManager) {
		super(pX, pY, pTiledTextureRegion, pVertexBufferObjectManager);
	}

	@Override
	protected void onManagedUpdate(float pSecondsElapsed) {
		super.onManagedUpdate(pSecondsElapsed);
	}

}
